<template>
  <Row type="flex">
    <Col flex="600px"> <h2 class="title2">平台业绩 <i>{{ config.page.total }}</i></h2></Col>
    <Col flex="550px">
      <Row :gutter="[12, 8]">
        <Col :span="10">
<!--          <Select v-model:value="config.params.type">
            <Option value="">全部工程类别</Option>
            <Option :value="item.id" v-for="item in dictionary.type">{{ item.dataValue }}</Option>
          </Select>-->
        </Col>
        <Col :span="10">
          <Input v-model:value="config.params.name" placeholder="请输入工程名称" />
        </Col>

        <Col :span="4" class="text-right">
          <Button type="primary" @click="changeHandler({current: 1},config)">查询</Button>
        </Col>
      </Row>
    </Col>
  </Row>

  <Table
      :columns="config.columns"
      :row-key="(record,index) => index"
      :data-source="config.list"
      :pagination="config.page"
      :loading="config.loading"
      @change="(pagination)=> changeHandler(pagination, config)"
      bordered
  >
    <template #indexSlot="{ index }">{{(config.page.current-1)*10+index+1}}</template>
    <template #name="{ text, record }">
      <router-link target="_blank" :to="{ path: `/activity/${record.activityId}` }" class="blue" >
        {{ text }}
      </router-link>
    </template>
  </Table>
</template>

<script lang="ts">
import {defineComponent, inject, onMounted, reactive, ref, toRefs} from 'vue';
import {Row, Col, Table, Input, Select, Button, Modal, Descriptions,} from 'ant-design-vue';
import { getProjectApi , getIndexCodeApi } from '/@/api/company';
import { parseTime } from '/@/utils';

const columns = [
  { title: '序号', dataIndex: 'index', width: 70, align: 'center', slots: ({ customRender: 'indexSlot' }) },
  { title: '工程名称', dataIndex: 'actiName',width: 250, slots: ({ customRender: 'name' })},
  { title: '工程类别', dataIndex: 'actiBusiName', width: 100 },
  { title: '工程内容', dataIndex: 'actiContent' ,width: 250},
  { title: '合同金额(万元)', dataIndex: 'fixedAmount', width: 130  },
  { title: '发包单位', dataIndex: 'contUnitName' },
  { title: '承接时间', dataIndex: 'utakeConfDate', width: 120, customRender: ({ record })=> parseTime(record.utakeConfDate)},
]

export default defineComponent({
  components: {
    Table , Row, Col, Input, Button, Select, Option: Select.Option,
    Modal,Descriptions,DescriptionsItem:Descriptions.Item,
  },
  setup() {
    const corpId = inject('corpId') as string;
    const visible = ref<boolean>(false);
    const recordDetail = ref<any>()
    const dictionary = reactive({
      type:[]
    })

    const config = reactive({
      columns: columns,
      list: [],
      loading: false,
      page: {
        total: 0,
        current: 1
      },
      params:{
        type:'',
        name:''
      }
    })


    const openDetail = data =>{
      recordDetail.value = data
      visible.value = true;
    }

    const changeHandler = (pagination, config) => {
      const { current } = pagination;
      let { loading, list, page  } = toRefs(config);
      let { type , name } =  config.params;
      loading.value = true;
      getProjectApi( { corpId, current ,type ,name }).then( data => {
        let { records, current, total } = data;
        list.value = records;
        loading.value = false;
        page.value = {current, total};
      })
    }

    const getIndexCode = (data,back) =>{
      getIndexCodeApi(data).then(res=>{
        if(back)back(res)
      })
    }

    const init = () => {
      changeHandler({current: 1}, config);

      getIndexCode('RY_REG_PROF',function (res){   //初始化 字典表
        dictionary.type = res;
      })
    }

    onMounted(init)

    return {
      config, changeHandler , dictionary ,visible ,recordDetail , parseTime,openDetail
    }
  },
})
</script>

<style lang="less" scoped>

.ant-col{
  padding-top: 16px;
  margin-bottom: 8px;
}

.ant-select ,.ant-btn{
  width: 100%;
}

.ant-col.text-right{
  padding-right: 0 !important;
}
</style>
